import { useState } from "react";
import { View } from "@tarojs/components";

type AllResultsProps = {
  item: {
    title: string,
    checkItems: string,
    nonComplianceItems: string,
    itemNumber: string,
    notApplicableItems: string,
  };
  index:string
};
const AllResults: React.FC<AllResultsProps> = ({item,index}) => {
  
  const [expandedIndex, setExpandedIndex] = useState(null);
  const handleExpanded = (index) => {
    if (expandedIndex === index) {
      setExpandedIndex(null);
    } else {
      setExpandedIndex(index);
    }
  };
  return (
    <View className="w-full p-3 bg-white rounded-lg">
      <View >
          <View>
            <View className="flex justify-between">
              <View className='text-blue-500'>
                {index + 1}、{item.title}
              </View>
              <View className='text-blue-500' onClick={() => handleExpanded(index)}>
                {expandedIndex === index ? "收起" : "展开"}
              </View>
            </View>
            <View>
              {expandedIndex === index && (
                <View className="pt-2" >
                  <View className="py-1">检查项数: {item.checkItems}</View>
                  <View className="py-1">不符合项数: {item.nonComplianceItems}</View>
                  <View className="py-1">项目序号: {item.itemNumber}</View>
                  <View className="py-1">不适用项数: {item.notApplicableItems}</View>
                </View>
              )}
            </View>
          </View>
      </View>
    </View>
  );
};

export default AllResults;
